package leetcode_501_600;

import node.TreeNode;

public class LeeCode_572 {
    public static void main(String[] args) {

    }
    private static boolean isSubtree(TreeNode root, TreeNode subRoot) {
        if (root == null && subRoot == null)
            return true;
        if (root == null || subRoot == null)
            return false;
        boolean f1 = false, f2 = false, f3 = false;
        if (root.val == subRoot.val){
            f1 = dfs(root, subRoot);
        }
        f2 = isSubtree(root.left, subRoot);
        f3 = isSubtree(root.right, subRoot);
        return f1 || f2 || f3;
    }
    private static boolean dfs(TreeNode node, TreeNode son){
        if (node == null && son == null)
            return true;
        if (node == null || son == null)
            return false;
        if (node.val != son.val){
            return false;
        }
        return dfs(node.left, son.left) && dfs(node.right, son.right);
    }
}
